// 搭建本地nodejs服务
const express = require('express');
// 引入bodyParser库 来处理POST请求
const bodyParser = require('body-parser');

// 创建本地服务
const app = express();

// app.use() 接收中间件处理函数  extended: true 定义是否处理非标准的请求
// 处理中间件 bodyParser.urlencoded -实现Post请求传递数据 表单序列化
// 顺序必须在使用路由前面
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

// 解决所有接口的跨域问题
app.all('*', (req, res, next) => {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Arrow-methods', 'POST,GET');
    next();
});

// 导入路由文件
const getHomeDatasRouter = require('./routes/getHomeDatas');
const getListDatasRouter = require('./routes/getListDatas');
const getDetailRouter = require('./routes/getDetail');
const searchActionRouter = require('./routes/searchAction');
const accountRouter = require('./routes/account');
const codeRouter = require('./routes/code');
const userInfoRouter = require('./routes/userInfo');
const planRouter = require('./routes/plan');

// 使用路由
app.use('/', getHomeDatasRouter);
app.use('/', getListDatasRouter);
app.use('/', getDetailRouter);
app.use('/', searchActionRouter);
app.use('/userLogin', accountRouter);
app.use('/userLogin', codeRouter);
app.use('/userInfo', userInfoRouter);
app.use('/plan', planRouter);

// 监听3000端口
app.listen(8080, () => {
    console.log('我是8080端口');
});


